<?php
class VES_VendorsWarehouse_Block_Account_Edit_Tab_Warehouse_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    
    public function __construct()
    {
        parent::__construct();
        $this->setUseAjax(true);
        $this->setId('warehouse_address_links');
        $this->setDefaultSort('number');
        $this->setDefaultDir('ASC');
    }
    protected function _getStore()
    {
        return Mage::app()->getStore();
    }
    
    protected function _prepareCollection()
    {
        $vendor_id=Mage::getSingleton('vendors/session')->getId();
        $collection = Mage::getModel('vendorswarehouse/address')->getCollection()->addFieldToFilter("vendor_id",array("eq"=>$vendor_id));
        
        $collection->getSelect()->join(array('warehouse_detail' => 'ves_vendor_warehouse_details'), 'warehouse_detail.wid = entity_id');
        $this->setCollection($collection);
       parent::_prepareCollection();
    }
    
    protected function _prepareColumns()
    {
        $this->addColumn('number', array(
            'header' => Mage::helper('vendorswarehouse')->__('仓库编号'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'number',
        ));
        $this->addColumn('sender_zip_code', array(
            'header' => Mage::helper('vendorswarehouse')->__('仓库编码'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'sender_zip_code',
        ));

        $this->addColumn('sender_address', array(
            'header' => Mage::helper('vendorswarehouse')->__('仓库地址'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'sender_address',
           ));
        $this->addColumn('sender_contact', array(
            'header' => Mage::helper('vendorswarehouse')->__('负责人'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'sender_contact',
        ));
        $this->addColumn('sender_phone', array(
            'header' => Mage::helper('vendorswarehouse')->__('负责人电话'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'sender_phone',
        ));
        $this->addColumn('statused', array(
            'header' => Mage::helper('vendorswarehouse')->__('状态'),
            'align' =>'center',
            'width' => '50px',
            'index' => 'status',
            'type' => 'options',
            'options' => Mage::getSingleton('vendorswarehouse/address')->getAvailableStatuses(),
        ));
        
        $this->addColumn('action',
            array(
                'header'    => Mage::helper('catalog')->__('操作'),
                'type'      => 'action',
				'width' => '60px',
                'filter'    => false,
                'sortable'  => false,
                'renderer' => 'VES_VendorsWarehouse_Block_Widget_Grid_Column_Renderer_AddressActions',
            ));
        return parent::_prepareColumns();
    }
    public function getGridUrl()
    {
        return $this->getUrl('*/warehouse_address/addressgrid', array('_current'=>true));
    }
    
    public function getRowUrl($item)
    {
        return false;
    }
}